package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SmCustomizedPrice;
import com.ruoyi.project.system.service.ISmCustomizedPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户产品定制Controller
 *
 */
@RestController
@RequestMapping("/system/price")
public class SmCustomizedPriceController extends BaseController
{
    @Autowired
    private ISmCustomizedPriceService smCustomizedPriceService;

    /**
     * 查询用户产品定制列表
     */
    @PreAuthorize("@ss.hasPermi('system:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmCustomizedPrice smCustomizedPrice)
    {
        startPage();
        List<SmCustomizedPrice> list = smCustomizedPriceService.selectSmCustomizedPriceList(smCustomizedPrice);
        return getDataTable(list);
    }

    /**
     * 导出用户产品定制列表
     */
    @PreAuthorize("@ss.hasPermi('system:price:export')")
    @Log(title = "用户产品定制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SmCustomizedPrice smCustomizedPrice)
    {
        List<SmCustomizedPrice> list = smCustomizedPriceService.selectSmCustomizedPriceList(smCustomizedPrice);
        ExcelUtil<SmCustomizedPrice> util = new ExcelUtil<SmCustomizedPrice>(SmCustomizedPrice.class);
        util.exportExcel(response, list, "用户产品定制数据");
    }

    /**
     * 获取用户产品定制详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:price:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(smCustomizedPriceService.selectSmCustomizedPriceById(id));
    }

    /**
     * 新增用户产品定制
     */
    @PreAuthorize("@ss.hasPermi('system:price:add')")
    @Log(title = "用户产品定制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmCustomizedPrice smCustomizedPrice)
    {
        return toAjax(smCustomizedPriceService.insertSmCustomizedPrice(smCustomizedPrice));
    }

    /**
     * 修改用户产品定制
     */
    @PreAuthorize("@ss.hasPermi('system:price:edit')")
    @Log(title = "用户产品定制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmCustomizedPrice smCustomizedPrice)
    {
        return toAjax(smCustomizedPriceService.updateSmCustomizedPrice(smCustomizedPrice));
    }

    /**
     * 删除用户产品定制
     */
    @PreAuthorize("@ss.hasPermi('system:price:remove')")
    @Log(title = "用户产品定制", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(smCustomizedPriceService.deleteSmCustomizedPriceByIds(ids));
    }
}
